from infrastructure.networks.generic import *
from infrastructure.networks.recurrent import *
from infrastructure.datasets.generic import *
import math

#activation_s = lambda x :  3 * math.tanh(x)
#activation_dervative_s = lambda x : 3 * (1 - math.tanh(x)**2)

activation_s = lambda x :  2.0  / (1.0 + math.exp(-x))
activation_dervative_s = lambda x : 2.0  * exp(-x)**2 / ((1.0 + math.exp(-x))**2)

activation = vectorize(activation_s)
activation_dervative = vectorize(activation_dervative_s)
spread = 0.4
center = 0

net = RecurrentNetwork()
net.input = GenericLayer(1)
net.output = GenericLayer(1)#,activation)

h1 = net.set_hidden(GenericLayer(8,activation))

l1 = net.set_link(GenericLink(net.input,h1,spread,center))
l2 = net.set_link(RecurrentLink(h1,h1,spread,center))
l3 = net.set_link(GenericLink(h1,net.output,spread,center))

trainer = None
U = True
for i in xrange(3):
    dataset = GenericDataset()
    dataset.load_training_file('data_prepared',(1,1))
    trainer = RecurrentTrainer(net, dataset, activation_dervative, activation_dervative_s, 0.30)
    trainer.train(1500, U)
    if i == 2:
        U = False

trainer.draw_desired_output()
#net.str_layers_full()